import dt from '@dt/dt'
import clueCustomerMgr from '@/biz/customer/clueCustomer.js'
import dateOpt from '@/biz/option/date.js'
import nameOpt from '@/biz/option/name.js'
import table from '@/components/dt/table/render.js'
import channelMgr from '@/biz/channel/channel'
let _this = null;

let acquisitionMethodOption = [
  { key: 1, value: '客户授权' },
  { key: 2, value: '客户来电' },
  { key: 3, value: '手动分配' },
  { key: 4, value: '场外报备' },
  { key: 5, value: '手动录入' },
  { key: 6, value: '运营导入' },
]

let customerStatusOptions = [
  { key: '首访', value: '首访' },
  { key: '回笼', value: '回笼' },
  { key: '认购', value: '认购' },
  { key: '签约', value: '签约' },
  { key: '全款', value: '全款' },
  { key: '交房', value: '交房' },
]


const sendThis = (vm, ) => {
  _this = vm;

};
export default {
  sendThis,
  columns: [{
      field: 'customerPhone',
      minWidth: 130,
      fixed: 'left',
      header: {
        filter: {
          title: '线索手机号码',
          key: 'cluePhone',
          placeholder: '请输入线索手机号码',
          input: {}
        }
      }
    },
    {
      field: 'wechat',
      title: '微信号',
      minWidth: 200,
      header: {
        filter: {
          title: '微信号',
          key: 'wechat',
          placeholder: '请输入微信号',
          input: {}
        }
      },
    },
    {
      title: '自获客打法',
      field: 'planName',
      minWidth: 160,
      align: 'center',
      header: {
        filter: {
          title: '自获客打法',
          key: 'planIds',
          placeholder: '请选择',
          load: (o) => {
            let params = {}
            channelMgr
              .planChannelChannelList(params)
              .then((res) => {
                res.forEach(item => {
                  item.key = item.planId
                  item.value = item.planName
                })
                o.select.options = res
              })
          },
          select: {
            options: [],
            multiple: true,
            filterable: true,
          }

        }
      }

    },

    {
      title: '营销工具',
      field: 'marketingTool',
      minWidth: 160,
      align: 'center',
      header: {
        filter: {
          title: '营销工具',
          key: 'marketingTools',
          placeholder: '请选择',
          select: {
            multiple: true,
            options: dt.dictInfo().marketingTool
          }
        }
      },


    },
    {
      title: '线索授权位置',
      field: 'authLocation',
      minWidth: 160,
      align: 'center',
      header: {
        filter: {
          title: '线索授权位置',
          key: 'authLocations',
          placeholder: '请选择',
          select: {
            multiple: true,
            options: dt.dictInfo().authLocation
          }
        }
      },


    },
    {
      field: 'marketingActivity',
      title: '营销活动',
      minWidth: 200,
      header: {
        filter: {
          title: '营销活动',
          key: 'marketingActivity',
          placeholder: '请输入营销活动',
          input: {}
        }
      },
    },


    {
      field: 'customerName',
      minWidth: 120,
      header: {
        filter: {
          title: '客户姓名',
          key: 'customerName',
          placeholder: '请输入客户姓名',
          input: {}
        }
      }
    }, {
      field: 'clueChannelName',
      minWidth: 160,
      header: {
        filter: {
          title: '线索来源渠道',
          key: 'clueChannelIds',
          placeholder: '请选择线索来源渠道',
          load: (o) => {
            o.select.options = clueCustomerMgr.channelSource()
          },
          select: {
            options: [],
            multiple: true,
            filterable: true,
          }
        }
      }
    }, {
      field: 'recommender',
      minWidth: 120,
      header: {
        filter: nameOpt.createPushPeople({
          key: 'recommender',
          title: '推荐人',
          to: (info) => {
            return {
              recommender: info.workNo
            }
          }
        })
      }
    }, {
      field: 'acquisitionMethod',
      minWidth: 160,
      header: {
        filter: {
          title: '获取方式',
          key: 'acquisitionMethodList',
          placeholder: '请选择获取方式',
          select: {
            options: acquisitionMethodOption,
            multiple: true,
            filterable: true,
          }
        }
      }
    },


    {
      field: 'createTime',
      minWidth: 160,
      header: {
        filter: dateOpt.range({
          title: '线索生成日期',
          placeholder: '请选择线索生成日期',
          startKey: 'startTime',
          endKey: 'endTime',
          // disabled: (date) => {
          //   return date.valueOf() > new Date().getTime()
          // },
          // check: (val) => {
          //   if (_this.$tool.dateDiff(val.startDate, val
          //       .endDate).Y >= 2) {
          //     // 日期最大跨度两年
          //     _this.$Message.warning('认购日期跨度至多两年。')
          //   }
          //   return !(_this.$tool.dateDiff(val.startDate, val
          //     .endDate).Y >= 2)
          // }
        }),
      },
      // cell: {
      //   value: (row) => row.createTime ? _this.$tool.dateFtt('yyyy/MM/dd hh:mm', row
      //     .createTime) : '',
      //   text: {}
      // }
    }, {
      field: 'isFirstPush',
      minWidth: 120,
      header: {
        filter: {
          title: '是否首推',
          key: 'isFirstPush',
          placeholder: '请选择是否首推',
          select: {
            options: [
              { key: 1, value: '是' },
              { key: 2, value: '否' },
            ],
          }
        }
      }
    }, {
      title: '推送次数',
      field: 'pushTimes',
      minWidth: 100,
    },

    {
      field: 'pushStatus',
      minWidth: 180,
      header: {
        filter: {
          title: '推送状态',
          key: 'pushStatus',
          placeholder: '请选择推送状态',
          select: {
            options: [
              { key: 1, value: '推送成功' },
              { key: 2, value: '推送失败' },
            ]
          }
        }
      }
    },

    {
      field: 'pushResult',
      minWidth: 180,
      header: {
        filter: {
          title: '推送结果说明',
          key: 'pushResultList',
          placeholder: '请选择推送结果说明',
          select: {
            options: [
              { key: '案场未关联线索渠道', value: '案场未关联线索渠道' },
              { key: '重复线索', value: '重复线索' },
              { key: '客户已到访', value: '客户已到访' },
              { key: '案场未配置承接人', value: '案场未配置承接人' },
              { key: '已推送至案场', value: '已推送至案场' },
              { key: '已推送至案场及顾问', value: '已推送至案场及顾问' },
            ],
            multiple: true,
            filterable: true,
          }
        }
      }
    }, {
      title: '推送事业部',
      field: 'pushDivision',
      minWidth: 150,
    },
    {
      title: '推送子公司',
      field: 'pushCompany',
      minWidth: 130,
    },
    {
      title: '推送事业处',
      field: 'pushOffice',
      minWidth: 180,
    },
    {
      title: '推送案场',
      field: 'pushBuilding',
      minWidth: 170,
    },
    {
      field: 'pushUserName',
      minWidth: 120,
      header: {
        filter: nameOpt.createPushPeople({
          key: 'pushUserNo',
          title: '推送顾问',
          to: (info) => {
            return {
              pushUserNo: info.workNo
            }
          }
        })
      }
    }, {
      field: 'isVisit',
      minWidth: 120,
      header: {
        filter: {
          title: '是否转到访线索',
          key: 'isVisit',
          placeholder: '请选择是否转到访线索',
          select: {
            options: [
              { key: 1, value: '是' },
              { key: 2, value: '否' },
            ],
          }
        }
      }
    }, {
      field: 'visitDate',
      minWidth: 160,
      header: {
        filter: dateOpt.range({
          title: '转到访日期',
          placeholder: '请选择转到访日期',
          startKey: 'visitStartTime',
          endKey: 'visitEndTime',
          // disabled: (date) => {
          //   return date.valueOf() > new Date().getTime()
          // },
          // check: (val) => {
          //   if (_this.$tool.dateDiff(val.startDate, val
          //       .endDate).Y >= 2) {
          //     // 日期最大跨度两年
          //     _this.$Message.warning('认购日期跨度至多两年。')
          //   }
          //   return !(_this.$tool.dateDiff(val.startDate, val
          //     .endDate).Y >= 2)
          // }
        }),
      },
      // cell: {
      //   value: (row) => row.createTime ? _this.$tool.dateFtt('yyyy/MM/dd hh:mm', row
      //     .createTime) : '',
      //   text: {}
      // }
    }, {
      field: 'visitChannel',
      minWidth: 160,
      header: {
        filter: {
          title: '到访渠道',
          key: 'visitChannelIds',
          placeholder: '请选择到访渠道',
          load: (o) => {
            o.select.options = clueCustomerMgr.channelSource()
          },
          select: {
            options: [],
            multiple: true,
            filterable: true,
          }
        }
      }
    }, {
      field: 'customerStatus',
      minWidth: 120,
      header: {
        filter: {
          title: '客户进度',
          key: 'customerStatusList',
          placeholder: '请选择客户进度',
          load: (o) => {
            o.select.options = customerStatusOptions
          },
          select: {
            options: [],
            multiple: true,
            filterable: true,
          }
        }
      }
    }, {
      field: 'isEffective',
      minWidth: 120,
      header: {
        filter: {
          title: '线索有效性',
          key: 'effectiveStatusList',
          placeholder: '请选择线索有效性',
          select: {
            multiple: true,
            options: [
              { key: 1, value: '有效' },
              { key: 2, value: '无效' },
              { key: 3, value: '失效' },
            ],
          }
        }
      }
    }, {
      title: '线索有效性说明',
      field: 'invalidDescription',
      minWidth: 180,
    },
    {
      title: '操作',
      field: 'operation',
      width: 120,
      align: 'center',
      fixed: 'right',

      slots: {
        default: (params, h) => {
          let btns = []
          btns.push({
            title: params.row.userCustomerId ? '查看详情' : '-',
            event: params.row.userCustomerId ? 'getDetail' : '',
            data: params.row
          })
          return table.cell.btns(_this, h, btns)
        }
      }
    }


  ],
}